//加载弹出层
layui.define('layer', function (exports) {
    $('head').append('<style>.my-layui-layer .layui-layer-btn {padding-top: 0 !important;}</style>');
    var layer = layui.layer,
        lutil = {
            error_alert: function (msg, callback) {
                layer.msg(msg, {
                    icon: 5,
                    anim: 6,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, callback || function () {

                })
            }
            , success_msg: function (msg, callback) {
                layer.msg(msg, {
                    icon: 1,
                    anim: 5,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, callback || function () {

                })
            }
            , warning_alert: function (msg) {
                layer.open({
                    title: '出错了哦'
                    , content: msg
                });
            }
            , my_confirm: function (title, msg, callback, cancel) {
                if (typeof msg === 'function')
                    cancel = callback, callback = msg, msg = title, title = '提示';
                if (!msg)
                    msg = title, title = '提示';
                layer.confirm(msg, {icon: 3, title: title, offset: '10%', closeBtn: 0}, function (index) {
                    callback && callback();
                    layer.close(index);
                }, function (index) {
                    cancel && cancel();
                    layer.close(index);
                });
            }
            , open_iframe: function (title, url, w, h, end) {
                title = title || false;
                url = url || "404.html";
                w = w || ($(window).width() * 0.9);
                h = h || ($(window).height() - 50);
                layer.open({
                    type: 2,
                    area: [w + (typeof w === 'string' && w.indexOf('%') > 0 ? '' : 'px'), h + (typeof h === 'string' && h.indexOf('%') > 0 ? '' : 'px')],
                    fix: false, //不固定
                    maxmin: true,
                    shadeClose: true,
                    shade: 0.4,
                    title: title,
                    content: url,
                    end: end
                });
            }, open_page: function (title, content, callback, cancel, w, h, config) {
                if (typeof cancel !== 'function')
                    config = h, h = w, w = cancel, cancel = null;
                if (typeof w === 'object')
                    config = w, h = w = null;
                if (typeof h === 'object')
                    config = h, h = null;
                config = config || {};
                if (config['success']) config['my-success'] = config['success'], delete config['success'];
                w = w || ($(window).width() * 0.9);
                h = h || ($(window).height() - 50);
                layer.open($.extend({
                    type: 1,
                    area: [w + (/^\d+(px)|(%)$/.test(w) > 0 ? '' : 'px'), h + (/^\d+(px)|(%)$/.test(h) > 0 ? '' : 'px')],
                    fix: false, //不固定
                    maxmin: true,
                    shadeClose: true,
                    shade: 0.4,
                    title: title || false,
                    btn: ['提交', '取消'],
                    content: content || '',
                    success: function (layero, index) {
                        $('#layui-layer' + index).addClass('my-layui-layer');
                        var content = $('#layui-layer' + index + ' .layui-layer-content');
                        content.height(content.height() + 17);
                        config['my-success'] && config['my-success'](layero, index);
                    },
                    yes: function (index, layero) {
                        callback && callback(index, layero);
                    }, btn2: cancel, cancel: cancel
                }, config || {}));
            }
        };
    exports('lutil', lutil);
});